//
//  HBMembershipCell.m
//  HeartBeat
//
//  Created by karong on 2023/9/11.
//

#import "HBMembershipCell.h"
#import "HBGoodsModel.h"
#import "UIView+WSDraw.h"
#import "WSGradientColorView.h"

@interface HBMembershipCell ()
@property (weak, nonatomic) IBOutlet UIView *mainView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *discountTitleLabel;
@property (weak, nonatomic) IBOutlet WSGradientColorView *discountTitleView;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *descLabel;

@end
@implementation HBMembershipCell
- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setDataWithCoin:(HBGoodsModel *)object select:(BOOL)select {
    self.titleLabel.text = object.title;
    self.priceLabel.text = SF(@"$%.2f", object.price);
    if (object.give_coins > 0) {
        self.descLabel.text = SF(WSLocalized(@"贈幣：+ %ld"), (long)object.give_coins);
    }
    else {
        self.descLabel.text = @"";
    }
    [self setDiscountStatusWithObject:object];
    [self setSelectStatus:select];
}

- (void)setDataWithVip:(HBGoodsModel *)object select:(BOOL)select {
    self.titleLabel.text = object.title;
    self.priceLabel.text = SF(@"$%.2f", object.price);
    self.descLabel.text = KEmptyStr(object.vip_activity_desc);
    [self setDiscountStatusWithObject:object];
    [self setSelectStatus:select];
}

- (void) setDiscountStatusWithObject:(HBGoodsModel *)object {
    if (KIsNullOrEmpty(object.vip_activity_tag)) {
        self.discountTitleView.hidden = YES;
    }
    else {
        self.discountTitleView.hidden = NO;
        self.discountTitleLabel.text = object.vip_activity_tag;
        [self.discountTitleView setupRoundedCornersWithCutCorners:(UIRectCornerTopLeft | UIRectCornerBottomRight) withRadii:CGSizeMake(5, 5)];
    }
}

- (void)setSelectStatus:(BOOL)select {
    UIColor * borderColor = select?[UIColor colorFromHexRGB:@"DFC487"]:UIColor.clearColor;
    UIColor * bgColor = select?[UIColor colorFromHexRGB:@"FFF8EE"]:UIColor.bg_gray_f2f2f2;
    self.mainView.layer.borderColor = borderColor.CGColor;
    self.mainView.backgroundColor = bgColor;
}
@end
